package org.game.log;

import org.bean.PlayerInfo;
import org.game.cache.ServerCache;
import org.game.constant.GameConstant;
import org.game.db.bean.Player;
import org.game.db.cache.PlayerCache;

import com.sojoys.artifact.manager.PropManager;
import com.sojoys.artifact.tools.SK_Plus;

/**
 * 日志
 * Created by fxf on 2017/7/20.
 */
public interface IGameLogger {

    String QUOTE = "'";
    String COMMA = ",";

    default SK_Plus getPlayerInfo(int pid) {
        PlayerInfo playerInfo = ServerCache.getPlayerInfoByPid(pid);
        SK_Plus result = SK_Plus.newSK_Plus();
        addField(result,PropManager.get(GameConstant.GAME_SERVER_ID));
        result.as(playerInfo.getPid(),COMMA);
        addField(result,playerInfo.getName());
        result.as(playerInfo.getLvl(),COMMA);
        result.as(playerInfo.getVip(),COMMA);
        Player player = PlayerCache.me().getById(pid);
        if (player!=null && player.getPlayerProxy().getAccountInfo() != null) {
        	addField(result, player.getPlayerProxy().getAccountInfo().getChannelId());
        	addField(result, player.getPlayerProxy().getAccountInfo().getChannelAppId());
		}else {
			addField(result, 0);
			addField(result, 0);
		}
        
        return result;
    }

    default SK_Plus addField(SK_Plus result ,String field){
    	result.as(QUOTE,field,QUOTE,COMMA);
        return result;
    }
    
    default SK_Plus addField(SK_Plus result ,boolean field){
    	result.as(field ? 1 : 0,COMMA);
        return result;
    }
    
    default SK_Plus addField(SK_Plus result ,Number field){
    	result.as(field,COMMA);
        return result;
    }
    
    default SK_Plus AddNowDateAndEnd(SK_Plus result ,Number field){
    	result.as(QUOTE,field,QUOTE);
        return result;
    }
}
